package com.hs.cglib.mixin;


import net.sf.cglib.proxy.Mixin;

/**
 * 类似 连续继承，有方法覆盖的可能
 */
public class MixinDemo {
    public static void main(String[] args) {
        Class<?>[] interfaces = new Class[]{MyInterfaceB.class,MyInterfaceA.class};
        Object[] delegates = new Object[]{new MyInterfaceBImpl(),new MyInterfaceAImpl()};

        Object o = Mixin.create(interfaces, delegates);

        MyInterfaceA a = (MyInterfaceA) o;
        a.methodA();
        a.method();

        MyInterfaceB b = (MyInterfaceB) o;
        b.methodB();
        b.method();
    }
}

interface MyInterfaceA {
    public void method();
    public void methodA();
}

interface MyInterfaceB {
    public void methodB();
    public void method();
}

class MyInterfaceAImpl implements MyInterfaceA {

    public void methodA() {
        System.out.println("MyInterfaceAImpl.methodA()");
    }
    public void method() {
        System.out.println("MyInterfaceAImpl.method()");
    }
}

class MyInterfaceBImpl implements MyInterfaceB {
    public void method() {
        System.out.println("MyInterfaceBImpl.method()");
    }
    public void methodB() {
        System.out.println("MyInterfaceBImpl.methodB()");
    }
}